home *** CD-ROM | disk | FTP | other *** search
/ .net 2002 March / DotNetMagazine-Issue107-Coverdisc-NET107-02-03-PCMac.bin / pc / PC Software / picks / HTTrack / httrack-3.22-3.exe / {app} / src_win / WinHTTrack / OptionTab7.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-18  |  9.1 KB  |  328 lines

  1. // OptionTab7.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Shell.h"
  6. #include "OptionTab7.h"
  7. #include "AddFilter.h"
  8.  
  9. /* basic HTTrack defs */
  10. extern "C" {
  11.   #include "htsglobal.h"
  12.   #include "htsbase.h"
  13. }
  14.  
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22. // COptionTab7 property page
  23.  
  24. IMPLEMENT_DYNCREATE(COptionTab7, CPropertyPage)
  25.  
  26. COptionTab7::COptionTab7() : CPropertyPage(COptionTab7::IDD)
  27. {
  28.   // Patcher titre
  29.   if (LANG_T(-1)) {    // Patcher en franÁais
  30.     m_psp.pszTitle=LANG(LANG_IOPT7); // titre
  31.     m_psp.dwFlags|=PSP_USETITLE;
  32.   }
  33.   m_psp.dwFlags|=PSP_HASHELP;
  34.   //
  35.     //{{AFX_DATA_INIT(COptionTab7)
  36.     m_url2 = _T("");
  37.     //}}AFX_DATA_INIT
  38. }
  39.  
  40. COptionTab7::~COptionTab7()
  41. {
  42. }
  43.  
  44. void COptionTab7::DoDataExchange(CDataExchange* pDX)
  45. {
  46.     CPropertyPage::DoDataExchange(pDX);
  47.     //{{AFX_DATA_MAP(COptionTab7)
  48.     DDX_Text(pDX, IDC_URL2, m_url2);
  49.     //}}AFX_DATA_MAP
  50. }
  51.  
  52.  
  53. BEGIN_MESSAGE_MAP(COptionTab7, CPropertyPage)
  54.     //{{AFX_MSG_MAP(COptionTab7)
  55.     ON_BN_CLICKED(IDC_ADD1, OnAdd1)
  56.     ON_BN_CLICKED(IDC_ADD2, OnAdd2)
  57.     ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
  58.     ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
  59.     ON_BN_CLICKED(IDC_CHECK3, OnCheck3)
  60.     //}}AFX_MSG_MAP
  61.   ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  62. END_MESSAGE_MAP()
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // COptionTab7 message handlers
  66.  
  67. void NewFilter(int i,char* s) {  // 0: forbid 1: accept
  68.   CAddFilter AddF;
  69.   AddF.type=i;
  70.   if (AddF.type==0)
  71.     AddF.m_addtype=LANG(LANG_B20); /*"Links following this rule will be forbidden:"*/
  72.   else
  73.     AddF.m_addtype=LANG(LANG_B21); // "Links following this rule will be accepted:";
  74.   if (AddF.DoModal()==IDOK) {
  75.     char query[256],t[256],as[256];
  76.     char* q;
  77.     strcpybuff(s,"");
  78.     strcpybuff(query,AddF.m_afquery);
  79.     q=query;
  80.     
  81.     if (AddF.m_aftype==10) {
  82.       if (i==0)
  83.         strcpybuff(s,"-");
  84.       else
  85.         strcpybuff(s,"+");
  86.       strcatbuff(s,"*");
  87.     } else {
  88.       while(strlen(q)>0) {
  89.         while ((*q==' ') || (*q==',')) q++;
  90.         strcpybuff(t,"");
  91.         {  // prochain (sÈparÈ par des ,)
  92.           char *a,*b;
  93.           a=strchr(q,' ');
  94.           b=strchr(q,',');
  95.           if (a && b) {  // dÈpartager
  96.             if ((int) b < (int) a)
  97.               a=b;
  98.           } else if (b) a=b;
  99.           
  100.           if (a) {
  101.             strcpybuff (t,"");
  102.             strncat(t,q,(int) a-(int) q);
  103.             q=a+1;
  104.           } else {
  105.             strcpybuff(t,q);
  106.             strcpybuff(q,"");
  107.           }
  108.         }
  109.         
  110.         if (strlen(t)>0) {
  111.           strcpybuff(as,"");
  112.           switch (AddF.m_aftype) {
  113.           case 0:  // ext
  114.             sprintf(as,"*.%s",t);
  115.             break;
  116.           case 1:  // contient
  117.             sprintf(as,"*/*%s*",t);
  118.             break;
  119.           case 2:  // this one
  120.             sprintf(as,"*/%s",t);
  121.             break;
  122.           case 3:  // folder contains
  123.             sprintf(as,"*/*%s*/*",t);
  124.             break;
  125.           case 4:  // this folder
  126.             sprintf(as,"*/%s/*",t);
  127.             break;
  128.           case 5:  // domaine
  129.             sprintf(as,"*[name].%s/*",t);
  130.             break;
  131.           case 6:  // contien
  132.             sprintf(as,"*[name].*[name]%s*[name].*[name]/*",t);
  133.             break;
  134.           case 7:  // host
  135.             sprintf(as,"%s/*",t);
  136.             break;
  137.           case 8:  // link contient
  138.             sprintf(as,"*%s*",t);
  139.             break;
  140.           case 9:  // lien exact
  141.             sprintf(as,"%s",t);
  142.             break;
  143.           }
  144.           if (strlen(as)>0) {
  145.             if (i==0)
  146.               strcatbuff(s,"-");
  147.             else
  148.               strcatbuff(s,"+");
  149.             strcatbuff(s,as);
  150.             strcatbuff(s,"\x0d\x0a");
  151.           }
  152.         }
  153.       }
  154.       
  155.     }
  156.  
  157.   } else strcpybuff(s,"");
  158. }
  159.  
  160.  
  161. void COptionTab7::OnAdd1() 
  162. {
  163.   char s[256]; s[0]='\0';
  164.   NewFilter(0,s);
  165.   if (strlen(s)>0) {
  166.     char tempo[HTS_URLMAXSIZE*4];
  167.     {
  168.       CString st;
  169.       GetDlgItemText(IDC_URL2,st);
  170.       strcpybuff(tempo,st);
  171.     }
  172.     if (strlen(tempo)>0) {
  173.       if ((tempo[strlen(tempo)-1]!=' ') && (tempo[strlen(tempo)-1]!='\n') && (tempo[strlen(tempo)-1]!=13))
  174.         strcatbuff(tempo,"\x0d\x0a");
  175.     }
  176.     strcatbuff(tempo,s);
  177.     //    m_url2=tempo;
  178.     SetDlgItemText(IDC_URL2,tempo);
  179.   }
  180. }
  181.  
  182. void COptionTab7::OnAdd2() 
  183. {
  184.   char s[256]; s[0]='\0';
  185.   NewFilter(1,s);
  186.   if (strlen(s)>0) {
  187.     char tempo[HTS_URLMAXSIZE*2];
  188.     {
  189.       CString st;
  190.       GetDlgItemText(IDC_URL2,st);
  191.       strcpybuff(tempo,st);
  192.     }
  193.     if (strlen(tempo)>0) {
  194.       if ((tempo[strlen(tempo)-1]!=' ') && (tempo[strlen(tempo)-1]!='\n') && (tempo[strlen(tempo)-1]!=13))
  195.         strcatbuff(tempo,"\x0d\x0a");
  196.     }
  197.     strcatbuff(tempo,s);
  198.     //    m_url2=tempo;
  199.     SetDlgItemText(IDC_URL2,tempo);
  200.   }
  201. }
  202.  
  203. BOOL COptionTab7::OnInitDialog() 
  204. {
  205.     CPropertyPage::OnInitDialog();
  206.   EnableToolTips(true);     // TOOL TIPS
  207.  
  208.   // mode modif ‡ la volÈe
  209.   if (modify==1) {
  210.     GetDlgItem(IDC_ADD1) ->ModifyStyle(0,WS_DISABLED);
  211.     GetDlgItem(IDC_ADD2) ->ModifyStyle(0,WS_DISABLED);
  212.     GetDlgItem(IDC_URL2) ->ModifyStyle(0,WS_DISABLED);
  213.     GetDlgItem(IDC_STATIC_finfo) ->ModifyStyle(0,WS_DISABLED);
  214.     GetDlgItem(IDC_STATIC_tip) ->ModifyStyle(0,WS_DISABLED);
  215.   } else {
  216.     GetDlgItem(IDC_ADD1) ->ModifyStyle(WS_DISABLED,0);
  217.     GetDlgItem(IDC_ADD2) ->ModifyStyle(WS_DISABLED,0);
  218.     GetDlgItem(IDC_URL2) ->ModifyStyle(WS_DISABLED,0);
  219.     GetDlgItem(IDC_STATIC_finfo) ->ModifyStyle(WS_DISABLED,0);
  220.     GetDlgItem(IDC_STATIC_tip) ->ModifyStyle(WS_DISABLED,0);
  221.   }
  222.  
  223.   // Patcher l'interface pour les FranÁais ;-)
  224.   if (LANG_T(-1)) {    // Patcher en franÁais
  225.     SetWindowText(LANG(LANG_B9)); // "Filtres");
  226.     SetDlgItemText(IDC_STATIC_finfo,LANG(LANG_B10)); // "Vous pouvez exclure ou accepter plusieurs URLs ou liens, en utilisant les jokers\nVous pouvez utiliser les virgules ou les espaces entre les filtres\nExemple: +*.zip,-www.*.com,-www.*.edu/cgi-bin/*.cgi");
  227.     SetDlgItemText(IDC_ADD1,LANG(LANG_B11)); // "Exclure lien(s)..");
  228.     SetDlgItemText(IDC_ADD2,LANG(LANG_B12)); // "Accepter lien(s)..");
  229.     SetDlgItemText(IDC_STATIC_tip,LANG(LANG_B13)); // "Conseil: Si vous voulez accepter tous les fichiers gif d'un site, utilisez quelque chose comme +www.monweb.com/*.gif\n(+*.gif autorisera TOUS les fichiers gif sur TOUS les sites)");
  230.   }
  231.  
  232.     return TRUE;  // return TRUE unless you set the focus to a control
  233.                   // EXCEPTION: OCX Property Pages should return FALSE
  234. }
  235.  
  236.  
  237.  
  238. // ------------------------------------------------------------
  239. // TOOL TIPS
  240. //
  241. // ajouter dans le .cpp:
  242. // remplacer les deux Wid1:: par le nom de la classe::
  243. // dans la message map, ajouter
  244. // ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  245. // dans initdialog ajouter
  246. // EnableToolTips(true);     // TOOL TIPS
  247. //
  248. // ajouter dans le .h:
  249. // char* GetTip(int id);
  250. // et en generated message map
  251. // afx_msg BOOL OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult );
  252. BOOL COptionTab7::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  253. {
  254.   TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
  255.   UINT nID =pNMHDR->idFrom;
  256.   if (pTTT->uFlags & TTF_IDISHWND)
  257.   {
  258.     // idFrom is actually the HWND of the tool
  259.     nID = ::GetDlgCtrlID((HWND)nID);
  260.     if(nID)
  261.     {
  262.       char* st=GetTip(nID);
  263.       if (st != "") {
  264.         pTTT->lpszText = st;
  265.         pTTT->hinst = AfxGetResourceHandle();
  266.         return(TRUE);
  267.       }
  268.     }
  269.   }
  270.   return(FALSE);
  271. }
  272. char* COptionTab7::GetTip(int ID)
  273. {
  274.   switch(ID) {
  275.     case IDC_ADD1: return LANG(LANG_C1);   /*"Add refuse filter"*/ break;
  276.     case IDC_ADD2: return LANG(LANG_C2);   /*"Add accept filter"*/ break;
  277.     case IDC_URL2: return LANG(LANG_C3);   /*"Extra filters"*/ break;
  278.   }
  279.   return "";
  280. }
  281. // TOOL TIPS
  282. // ------------------------------------------------------------
  283.  
  284. void COptionTab7::EnsureIncluded(BOOL state, CString filter)  {
  285.   /* wipe all selected filters */
  286.   CString st;
  287.   CString ftok=filter;
  288.   GetDlgItemText(IDC_URL2,st);
  289.   ftok+=" ";
  290.   while(ftok.Find(' ')>=0) {
  291.     CString token=ftok.Mid(0,ftok.Find(' '));
  292.     ftok=ftok.Mid(ftok.Find(' ')+1);
  293.     ftok.TrimLeft();
  294.     st.Replace(token,"");
  295.     st.Replace("\r"," ");
  296.     st.Replace("\t"," ");
  297.     st.Replace("  "," ");
  298.     st.Replace(" \n","\n");
  299.     st.Replace("\n ","\n");
  300.     st.Replace("\n\n","\n");
  301.   }
  302.   st.TrimLeft();
  303.   st.TrimRight();
  304.   /* add ? */
  305.   if (state) {
  306.     st+="\n";
  307.     st+=filter;
  308.   }
  309.   st.Replace("\n","\r\n");      // W32 compatible
  310.   SetDlgItemText(IDC_URL2,st);
  311. }
  312.  
  313.  
  314. void COptionTab7::OnCheck1() 
  315. {
  316.   EnsureIncluded(this->IsDlgButtonChecked(IDC_CHECK1),"+*.gif +*.jpg +*.png +*.tif +*.bmp");
  317. }
  318.  
  319. void COptionTab7::OnCheck2() 
  320. {
  321.   EnsureIncluded(this->IsDlgButtonChecked(IDC_CHECK2),"+*.zip +*.tar +*.tgz +*.gz +*.rar +*.z +*.exe");
  322. }
  323.  
  324. void COptionTab7::OnCheck3() 
  325. {
  326.   EnsureIncluded(this->IsDlgButtonChecked(IDC_CHECK3),"+*.mov +*.mpg +*.mpeg +*.avi +*.asf +*.mp3 +*.mp2 +*.rm +*.wav +*.vob +*.qt +*.vid +*.ac3 +*.wma +*.wmv");
  327. }
  328.